//
//  TravellerTableViewCell.m
//  Journey
//
//  Created by dllo on 16/5/25.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "TravellerTableViewCell.h"

@implementation TravellerTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self createTraveller];
    }
    return self;
}


-(void)createTraveller{
    self.timeLabel = [[UILabel alloc] init];
//    self.timeLabel.backgroundColor = [UIColor yellowColor];
    [self.contentView addSubview: self.timeLabel];
    
    self.cityLabel = [[UILabel alloc] init];
//    self.cityLabel.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:self.cityLabel];
    
    self.titleLabel = [[UILabel alloc] init];
//    self.titleLabel.backgroundColor = [UIColor cyanColor];
    [self.contentView addSubview:self.titleLabel];
    
    self.nameLabel = [[UILabel alloc] init];
 //   self.nameLabel.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:self.nameLabel];
    
    self.viewLabel = [[UILabel alloc] init];
//    self.viewLabel.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:self.viewLabel];
    
    self.replysLabel = [[UILabel alloc] init];
 //   self.replysLabel.backgroundColor = [UIColor magentaColor];
    [self.contentView addSubview:self.replysLabel];
    
    
}

-(void)layoutSubviews{
    [super layoutSubviews];
    self.timeLabel.frame = CGRectMake(10 * WIDTHC, 10 * WIDTHC, 200 * WIDTHC , 30 * WIDTHC);
    
  self.cityLabel.frame = CGRectMake(self.timeLabel.frame.size.width, 10 * WIDTHC, 150 * WIDTHC, 30 * WIDTHC);
  self.titleLabel.frame = CGRectMake(10 * WIDTHC, 40 * WIDTHC, self.contentView.frame.size.width, 40 * WIDTHC);
    self.titleLabel.textColor = [UIColor grayColor];
    self.nameLabel.frame = CGRectMake(10 * WIDTHC, 80 * WIDTHC, 150 * WIDTHC, 30 * WIDTHC);
    self.nameLabel.textColor = [UIColor grayColor];
    self.nameLabel.font = [UIFont systemFontOfSize:15];
    self.viewLabel.frame = CGRectMake(self.contentView.frame.size.width - 100, 80 * WIDTHC, 50 * WIDTHC, 30 * WIDTHC);
    self.viewLabel.font = [UIFont systemFontOfSize:15];
    self.viewLabel.textColor = [UIColor grayColor];
    self.replysLabel.frame = CGRectMake(self.viewLabel.frame.origin.x + 50, 80 * WIDTHC, 50 * WIDTHC, 30 * WIDTHC);
    self.replysLabel.font = [UIFont systemFontOfSize:15];
    self.replysLabel.textColor = [UIColor grayColor];
}


-(void)setTraveller:(TravellerModel *)traveller{
    _traveller = traveller;
    
    self.cityLabel.text = traveller.citys_str;
    self.titleLabel.text = traveller.title;
    self.nameLabel.text = traveller.username;
    self.viewLabel.text = [traveller.views stringValue];
    self.replysLabel.text = [traveller.replys stringValue];
    
    NSString *string = traveller.start_time;
    
    NSTimeInterval time = [string doubleValue]+ 28800;
     NSDate *detaildate=[NSDate dateWithTimeIntervalSince1970:time];
    //实例化一个NSDateFormatter对象
    NSDateFormatter*dateFormatter = [[NSDateFormatter alloc]init];
    //设定时间格式,这里可以设置成自己需要的格式
    [dateFormatter setDateFormat:@"yyyy.MM.dd"];
    NSString *currentDateStr = [dateFormatter stringFromDate:detaildate];
    
    NSString *str = traveller.end_time;
    NSTimeInterval interval = [str doubleValue]+ 28800;
    NSDate *detail=[NSDate dateWithTimeIntervalSince1970:interval];
    //实例化一个NSDateFormatter对象
    NSDateFormatter*Formatter = [[NSDateFormatter alloc]init];
    //设定时间格式,这里可以设置成自己需要的格式
    [Formatter setDateFormat:@"yyyy.MM.dd"];
    NSString *endString = [Formatter stringFromDate:detail];
    
    self.timeLabel.text = [NSString stringWithFormat:@"%@-%@",currentDateStr,endString];
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
